package {{.PackageNameExtend}};
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.emax.channel.provider.modules.invoicebalance.converter.{{.ClassName}}DTOConverter;
import com.emax.channel.provider.modules.invoicebalance.entity.{{.ClassName}}Entity;
import com.emax.channel.provider.modules.invoicebalance.manager.{{.ClassName}}Manager;
import {{.ExtendMap.RpcPackageName}}.dto.{{.ClassName}}DTO;
import {{.ExtendMap.RpcPackageName}}.service.{{.ClassName}}API;
import com.emax.zhenghe.common.api.vo.MyIPage;
import com.emax.zhenghe.common.api.vo.ResultX;
import com.emax.zhenghe.common.util.MyIPageUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import com.umpay.core.util.StringUtils;
import java.util.Objects;

/**
 * @Author {{.Author}}
 * @Date {{.Date}}
 */

@Slf4j
@DubboService
public class {{.ClassName}}ServiceImpl implements {{.ClassName}}API {
    @Resource
    private {{.ClassName}}Manager {{.LowerClassName}}Mapper;

    @Resource
    private {{.ClassName}}DTOConverter {{.LowerClassName}}DtoConverter;

    @Override
    public ResultX<MyIPage<{{.ClassName}}DTO>> page({{.ClassName}}DTO dto, long pageNo, long pageSize) {
        log.info("{{.ClassName}}ServiceAPI->page分页查询接口入参：{}", dto);
        IPage<{{.ClassName}}Entity> page = {{.LowerClassName}}Mapper.page(dto, pageNo, pageSize);
        log.info("{{.ClassName}}ServiceAPI->page分页查询接口出参(Size)：{}", page.getRecords().size());
        MyIPage<{{.ClassName}}DTO> result = MyIPageUtil.from(page, {{.LowerClassName}}DtoConverter::toDTO);
        return ResultX.success(result);
    }

    @Override
    public ResultX<List<{{.ClassName}}DTO>> query({{.ClassName}}DTO dto) {
        log.info("{{.ClassName}}ServiceAPI->dto查询接口入参：{}", dto);
        List<{{.ClassName}}Entity> result = {{.LowerClassName}}Mapper.query(dto);
        log.info("{{.ClassName}}ServiceAPI->dto查询接口出参(Size)：{}", result.size());
        List<{{.ClassName}}DTO> collect = result.stream().map({{.LowerClassName}}DtoConverter::toDTO).collect(Collectors.toList());
        return ResultX.success(collect);
    }

    @Override
    public ResultX<{{.ClassName}}DTO> queryById(Long id) {
        log.info("{{.ClassName}}ServiceAPI->queryById查询接口入参：{}", id);
        {{.ClassName}}Entity byId = {{.LowerClassName}}Mapper.getById(id);
        log.info("{{.ClassName}}ServiceAPI->queryById查询接口出参：{}", JSON.toJSONString(byId));
        if (byId == null) {
            return ResultX.error("未查询到数据");
        }
        return ResultX.success({{.LowerClassName}}DtoConverter.toDTO(byId));
    }

    @Override
    public ResultX<Void> insert({{.ClassName}}DTO dto) {
        log.info("{{.ClassName}}ServiceAPI->insert新增接口入参：{}", JSON.toJSONString(dto));
        boolean save = {{.LowerClassName}}Mapper.save({{.LowerClassName}}DtoConverter.fromDTO(dto));
        log.info("{{.ClassName}}ServiceAPI->insert新增接口出参：{}", save);
        if (save) {
            return ResultX.success();
        }
        return ResultX.error("新增失败");
    }

    @Override
    public ResultX<Void> updateById({{.ClassName}}DTO dto) {
        log.info("{{.ClassName}}ServiceAPI->updateById更新接口入参：{}", JSON.toJSONString(dto));
        boolean update = {{.LowerClassName}}Mapper.updateById({{.LowerClassName}}DtoConverter.fromDTO(dto));
        log.info("{{.ClassName}}ServiceAPI->updateById更新接口出参：{}", update);
        if (update) {
            return ResultX.success();
        }
        return ResultX.error("更新失败");
    }

    @Override
    public ResultX<Void> delete({{.ClassName}}DTO dto) {
        log.info("{{.ClassName}}ServiceAPI->delete删除接口入参：{}", JSON.toJSONString(dto));
        LambdaUpdateWrapper<{{.ClassName}}Entity> wrapper = new LambdaUpdateWrapper<{{.ClassName}}Entity>()
{{.ExtendMap.LambdaUpdateWrapper}}
        boolean remove = {{.LowerClassName}}Mapper.remove(wrapper);
        log.info("{{.ClassName}}ServiceAPI->delete删除接口出参：{}", remove);
        if (remove) {
            return ResultX.success();
        }
        return ResultX.error("删除失败");
    }

}